<!DOCTYPE html>
<html>
  <head>
    <title>
      灯
    </title>
    <meta charset="UTF-8"/>
  </head>
  <body>
    <img id="pic"  src="dengoff.jpg"/>
    <button onclick="kaiDeng()">开关</button>
  </body>
  <script>
    var i=1;
    function kaiDeng(){
    if(i==1){
    pic.src="dengon.jpg";
    i=0;
    }else{
          pic.src="dengoff.jpg";
          i=1;
       }
}
  </script>
</html>
